﻿using System;
using System.Collections.Generic;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Corretagem.Communication.Bovespa.Ordens.Negocio;

namespace Sinacor.UI.Bovespa.Corretagem.Communication
{
    public class Negocio : BaseCommunication
    {
        #region Construtor

        public Negocio(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }

        #endregion

        #region ConsultarBolsas

        public ModelCollection<Model.Bolsa> ConsultarBolsas()
        {
            ModelCollection<Model.Bolsa> retorno = null;
            INegocio servico = null;
            try
            {
                using (ServiceInstance<INegocio> service = new ServiceInstance<INegocio>())
                {
                    servico = service.TryGetInstance(this.Session);
                    Translator.DataContractToModel.Negocio negocio = new Translator.DataContractToModel.Negocio();
                    
                    List<BolsaResponse> bolsaresponse = servico.ConsultarBolsas();
                    retorno = negocio.ToNegocio(bolsaresponse);
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

            return retorno;
        }

        #endregion
    }
}
